Thinking in Ramda 7

Thinking in Ramda: Immutability and Arrays

Reading Array Elements

Ramda functions for reading array elements nth and slice and contains

1
2
3
4
5
const numbers = [10,20,30,40,50,60]
nth(3, numbers) // => 40 (0-based indexing)
nth(-2, numbers) // =>50 (negative numbers start from the right)
slice(2, 5, numbers) // => [30,40, 50] (see below)
contains(20, numbers) // => true

nth(0) equals head, nth(-1) equals last.

It also provides functions for accesing all-but-the-first element tail,all-but-the-last element init,the first N elements take(N), and the last N elments takeLast(N).

Adding, Updating, and Removing Array Elements

  • insert
  • update
  • append
  • prepend
  • update
  • concat
  • concatAfter = flip(concat)

Transforming Elements

  • update
  • adjust
  • evolve

Cite From « Thinking in Ramda: Immutability and Arrays »

文章目录
  1. 1. Thinking in Ramda: Immutability and Arrays
    1. 1.1. Reading Array Elements
    2. 1.2. Adding, Updating, and Removing Array Elements
    3. 1.3. Transforming Elements
,
Fork me on GitHub